import 'package:flutter/material.dart';
import 'package:get/get_utils/src/extensions/context_extensions.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/utils/helper.dart';

enum ButtonChooseType { selected, notSelected, noMore }

class ProductSkuListWidget extends StatelessWidget {
  final Function(dynamic, dynamic, dynamic)? onPressed;
  // final ButtonChooseType? bottomType;
  // final
  final List<dynamic>? skuList;
  final List<dynamic>? currentSelected;
  const ProductSkuListWidget({
    super.key,
    this.onPressed,
    required this.skuList,
    required this.currentSelected,
  });

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: context.width,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,

        children: [
          ...skuList!.asMap().entries.map((item) {
            return Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  item.value.name,
                  style: TextStyle(
                    color: AppColors.fontColorBlack,
                    fontSize: 16.px,
                  ),
                ),
                const SizedBox(height: 12),
                SingleChildScrollView(
                  scrollDirection: Axis.horizontal,
                  child: Row(
                    children: [
                      ...item.value.values.map((e) {
                        return GestureDetector(
                          onTap: () {
                            if (onPressed != null) {
                              print('e========${e.skuId}');
                              // return
                              onPressed!(item.value, item.key, e); // 这里传递具体的参数
                              // debugPrint(currentSelected?[index]);
                            }
                          },
                          child: Container(
                            margin: EdgeInsets.only(right: 8.px),
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(4.px),
                              border:
                                  currentSelected?[item.key] == e.value
                                      ? Border.all(
                                        width: 1.px,
                                        color: AppColors.fontColorGreen,
                                      )
                                      : Border.all(
                                        width: 1.px,
                                        color: AppColors.fontColor,
                                      ),
                              gradient: LinearGradient(
                                // 设置背景渐变色
                                begin: Alignment.topCenter,
                                end: Alignment.bottomCenter,
                                colors:
                                    currentSelected?[item.key] == e.value
                                        ? [
                                          Color.fromRGBO(53, 250, 169, 0.1),
                                          Color.fromRGBO(58, 99, 79, 0.1),
                                        ]
                                        : [
                                          Color.fromRGBO(223, 223, 223, 0.5),
                                          Color.fromRGBO(223, 223, 223, 0.5),
                                        ], // 渐变色
                              ),
                            ),
                            child: Padding(
                              padding: EdgeInsets.fromLTRB(
                                16.px,
                                2.px,
                                16.px,
                                2.px,
                              ),
                              child: Center(
                                child: Text(
                                  e.value,
                                  style: TextStyle(
                                    color: AppColors.fontColorBlack,
                                    fontSize: 12.px,
                                  ),
                                ),
                              ),
                            ),
                          ),
                        );
                      }),
                    ],
                  ),
                ),
                const SizedBox(height: 24),
              ],
            );
          }),
        ],
      ),

      //   ListView.builder(
      //     shrinkWrap: true,
      //     itemCount: skuList?.length,
      //     itemBuilder: (context, index) {
      //       final item = skuList?[index];
      //       //  print('${item.value}============sku.skuId=lllcj');
      //       // print('${item?.name}============sku.value=lllcj');
      //       //  print('${item?.quantity}============sku.quantity=lllcj');
      //       return
      //       Column(
      //         crossAxisAlignment: CrossAxisAlignment.start,
      //         children: [
      //           Text(
      //             item!.name,
      //             style: TextStyle(
      //               color: AppColors.fontColorBlack,
      //               fontSize: 16.px,
      //             ),
      //           ),
      //           const SizedBox(height: 12),
      //           SingleChildScrollView(
      //             scrollDirection: Axis.horizontal,
      //             child: Row(
      //               children: [
      //                 ...item.values.map((e) {
      //                   return GestureDetector(
      //                     onTap: () {
      //                       if (onPressed != null) {
      //                         print('e========${e.skuId}');
      //                         // return
      //                         onPressed!(item, index, e); // 这里传递具体的参数
      //                         // debugPrint(currentSelected?[index]);
      //                       }
      //                     },
      //                     child: Container(
      //                       margin: EdgeInsets.only(right: 8.px),
      //                       decoration: BoxDecoration(
      //                         borderRadius: BorderRadius.circular(4.px),
      //                         border:
      //                             currentSelected?[index] == e.value
      //                                 ? Border.all(
      //                                   width: 1.px,
      //                                   color: AppColors.fontColorGreen,
      //                                 )
      //                                 : Border.all(
      //                                   width: 1.px,
      //                                   color: AppColors.fontColor,
      //                                 ),
      //                         gradient: LinearGradient(
      //                           // 设置背景渐变色
      //                           begin: Alignment.topCenter,
      //                           end: Alignment.bottomCenter,
      //                           colors:
      //                               currentSelected?[index] == e.value
      //                                   ? [
      //                                     Color.fromRGBO(53, 250, 169, 0.1),
      //                                     Color.fromRGBO(58, 99, 79, 0.1),
      //                                   ]
      //                                   : [
      //                                     Color.fromRGBO(223, 223, 223, 0.5),
      //                                     Color.fromRGBO(223, 223, 223, 0.5),
      //                                   ], // 渐变色
      //                         ),
      //                       ),
      //                       child: Padding(
      //                         padding: EdgeInsets.fromLTRB(
      //                           16.px,
      //                           2.px,
      //                           16.px,
      //                           2.px,
      //                         ),
      //                         child: Center(
      //                           child: Text(
      //                             e.value,
      //                             style: TextStyle(
      //                               color: AppColors.fontColorBlack,
      //                               fontSize: 12.px,
      //                             ),
      //                           ),
      //                         ),
      //                       ),
      //                     ),
      //                   );
      //                 }),
      //               ],
      //             ),
      //           ),
      //           const SizedBox(height: 24),
      //         ],
      //       );
      //     },
      //   ),
    );
  }
}
